//
//  NSString+ZB.m
//  PaoPao
//
//  Created by xzb on 2018/4/1.
//  Copyright © 2018年 paopao. All rights reserved.
//

#import "NSString+ZB.h"

@implementation NSString (ZB)


- (NSString*)changeChinese
{
    NSMutableString *ms = [[NSMutableString alloc] initWithString:self];
    //将音标字母转换为有音标字母
    if (CFStringTransform((__bridge CFMutableStringRef)ms, 0, kCFStringTransformMandarinLatin, NO)) {
    }
    //将音标字母转换为普通字母
    if (CFStringTransform((__bridge CFMutableStringRef)ms, 0, kCFStringTransformStripDiacritics, NO)) {
    }
    //字符串去空格化
    NSString *replaceStr=  [ms stringByReplacingOccurrencesOfString:@" " withString:@""];
    
    return replaceStr;
}
/**
 *  @brief  去除空格
 *
 *  @return 去除空格后的字符串
 */
- (NSString *)zb_trimmingWhitespace
{
    return [self stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
}
/**
 *  @brief  去除字符串与空行
 *
 *  @return 去除字符串与空行的字符串
 */
- (NSString *)zb_trimmingWhitespaceAndNewlines
{
    return [self stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
}

/**
 *  @brief  JSON字符串转成NSDictionary
 *
 *  @return NSDictionary
 */
-(NSDictionary *)zb_dictionaryValue{
    NSError *errorJson;
    NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:[self dataUsingEncoding:NSUTF8StringEncoding] options:kNilOptions error:&errorJson];
    if (errorJson != nil) {
#ifdef DEBUG
        Log(@"fail to get dictioanry from JSON: %@, error: %@", self, errorJson);
#endif
    }
    return jsonDict;
}

- (BOOL)empty
{
    return self.length < 1;
}

@end
